<template>
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px; width: 100%"
  >
    <el-col>
      <!-- 左侧内容 -->
      <span>{{ treeNode.name }}</span>
    </el-col>
    <el-col :span="4">
      <!-- 右侧内容 -->
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ treeNode.manager }}</el-col>

        <el-col>
          <!-- 放置下拉菜单 -->
          <el-dropdown @command="handleCommand">
            <!-- 内容 -->
            <span>操作</span> <i class="el-icon-arrow-down"></i>
            <el-dropdown-menu slot="dropdown">
              <!-- 下拉选项 -->
              <el-dropdown-item command="add"> 添加子部门 </el-dropdown-item>
              <el-dropdown-item v-if="!isShow" command="edit">
                编辑部门
              </el-dropdown-item>
              <el-dropdown-item v-if="!isShow" command="del">
                删除部门
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartment } from "@/api/departments";
export default {
  name: "treeTools",
  props: {
    treeNode: {
      type: Object,
      required: true,
    },
    isShow: {
      type: Boolean,
      default: false,
    },
  },
  methods: {
    //操作下拉 编辑 添加 删除部门
    handleCommand(command) {
      if (command === "add") {
        this.$emit("addDepart", this.treeNode);
      } else if (command === "edit") {
        this.$emit("editDepart", this.treeNode);
      } else if (command === "del") {
        //点击删除部分弹是否确认删除
        this.$confirm("你确定要删除该组织部门吗")
          .then(() => {
            return delDepartment(this.treeNode.id);
          })
          .then(() => {
            this.$message.success("删除成功");
            //删除部门成功,重新渲染界面
            this.$emit("updataDepart");
          });
      }
    },
  },
};
</script>

<style>
</style>